package com.jielihaofeng.nio.mesageboundary;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;

/**
 * @description 演示半包常见客户端代码
 * @author Johnnie Wind
 * @date 2021/10/27 23:39
 */
public class Client {

    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("localhost",8080));
//        socketChannel.write(Charset.defaultCharset().encode("hello")); // 大于定义的ByteBuffer长度
//        socketChannel.write(Charset.defaultCharset().encode("你好")); // “你”完整输出，“好”乱码
        socketChannel.write(Charset.defaultCharset().encode("你好\n中国\n")); // “你”完整输出，“好”乱码
//        socketChannel.write(Charset.defaultCharset().encode("ab中")); // ab完整输出，“中”乱码
//        socketChannel.write(Charset.defaultCharset().encode("hellohellohellohello\nworldworldworldworld\n")); // “你”完整输出，“好”乱码
//        socketChannel.write(Charset.defaultCharset().encode("在凌晨三点钟\n克利夫兰机场在安检中\n")); // ab完整输出，“中”乱码
        System.in.read();
    }
}
